package com.milhouz.quizzdroid.bean;

import android.database.Cursor;

import com.milhouz.quizzdroid.db.QuizzDroidConstants;

public class User {

	private int mId;
	private String mUsername;
	private int mTotalQuestions;
	private int mNbGoodResponses;
	private float mMeanTimeMs;

	public User(final Cursor cursor) {
		if (cursor != null && cursor.moveToFirst()) {
			mId = cursor.getInt(cursor.getColumnIndex(QuizzDroidConstants.ID));
			mUsername = cursor.getString(cursor.getColumnIndex(QuizzDroidConstants.COLUMN_NAME_USERNAME));
			mTotalQuestions = cursor.getInt(cursor.getColumnIndex(QuizzDroidConstants.COLUMN_NAME_TOTAL_QUESTIONS));
			mNbGoodResponses = cursor.getInt(cursor.getColumnIndex(QuizzDroidConstants.COLUMN_NAME_NB_GOOD_RESPONSES));
			mMeanTimeMs = cursor.getFloat(cursor.getColumnIndex(QuizzDroidConstants.COLUMN_NAME_MEANTIME));
		}
	}

	public int getId() {
		return mId;
	}

	public String getUsername() {
		return mUsername;
	}

	public int getTotalQuestions() {
		return mTotalQuestions;
	}

	public int getNbResponses() {
		return mNbGoodResponses;
	}

	public float getMeanTimeMs() {
		return mMeanTimeMs;
	}

	public float getMeanTimeSec() {
		return mMeanTimeMs / 1000;
	}

	public void updateStats(boolean isGoodResponse, float meantime) {
		mTotalQuestions++;
		if (isGoodResponse) {
			mNbGoodResponses++;
		}
		mMeanTimeMs = (mMeanTimeMs + meantime) / 2;
	}

}
